package ucl.cs.stockbroker.common;

import java.rmi.RemoteException;
import java.util.ArrayList;

/**
 * StockBroker Remote Interface.
 * @author  Min Park, Saniul Ahmed, Kamil Olesiejuk
 * @version 1.0
 */
public interface StockBroker extends java.rmi.Remote {

	/**
	 * Allows the creation of an Account on the Stock Broker server, given required parameters.
	 * 
	 * @param name : String - the name of the account
	 * @param PIN : String 
	 * @return account number : int - the account number generated on the server essential
	 * for further interaction.
	 * @throws RemoteException - on remote communication errors. (with the client to pass the 
	 * 	account number back).
	 */
	int createAccount(String name, String PIN) throws RemoteException;

	/**
	 * Allows to get a reference to the desired account given the account number.
	 * 
	 * @param accountNumber : int - account number
	 * @return StockBrokerAccount - the account object reference 
	 * @throws RemoteException - on remote communication errors
	 * @throws NoSuchAccountException - if there is no such account in the database 
	 */
	StockBrokerAccount getAccount(int accountNumber) throws RemoteException,
			NoSuchAccountException;

	/**
	 * Provides a ArrayList<StockCompnyInfo> with information about the stock prices.
	 * 
	 * @return ArrayList<StockCompanyInfo>
	 * @throws RemoteException - on remote communication errors
	 */
	ArrayList<StockCompanyInfo> getRegisteredStock() throws RemoteException;

	/**
	 * Provides an array with StockAccountInfo objects, providing information about the 
	 * accounts in the server database.
	 * 
	 * @return StockBrokerAccountInfo[] - an array of StockBrokerAccountInfo objects containing
	 * existing account information.
	 * @throws RemoteException - on remote communication errors
	 */
	StockBrokerAccountInfo[] listAccounts() throws RemoteException;
	
	/**
	 * Returns a sorted array of StockBrokerAccountInfo objects corresponding 
	 * to all the StockBrockerAccount objects in the database.
	 * Used for the account ranking.
	 * 
	 * @return StockBrockerAccountInfo[]
	 * @throws RemoteException - on remote communication errors
	 */
	StockBrokerAccountInfo[] listAccountsRanked() throws RemoteException;

	/**
	 * Allows to terminate an account, given the account number and a valid PIN. 
	 * After successful PIN validation the method sells all the stock owned by this account
	 * at current price and returns the balance value of the account afterwards.
	 * 
	 * @param accountNumber : int - the number of the account to terminate
	 * @param PIN : String - PIN
	 * @return balance : double - the balance after selling all stock at current price.
	 * @throws RemoteException - on remote communication errors
	 * @throws NoSuchAccountException - if no such account exists in the database
	 * @throws WrongPINException - on invalid PIN
	 */

	double terminateAccount(int accountNumber, String PIN)
			throws RemoteException, NoSuchAccountException, WrongPINException;

}